#!/usr/bin/env bash

progress() {
    local GREEN CLEAN
    GREEN='\033[0;32m'
    CLEAN='\033[0m'
    printf "\n${GREEN}$@  ${CLEAN}\n" >&2
}

set -e

# Docker image name
# IMAGENAME=registry.cn-beijing.aliyuncs.com/ylg/distribution-web
DOCKER_TAG=$(date -u "+%Y%m%d-%H%M%S");

progress "Building jar file ..."
mvn package -Dmaven.test.skip=true

progress "Building ${IMAGENAME} docker image ... "
sudo docker build -t ${IMAGENAME}:${DOCKER_TAG} .

progress "push ${IMAGENAME} ......"
sudo docker push ${IMAGENAME}:${DOCKER_TAG}

progress "delete ${IMAGENAME} images ......"
sudo docker rmi ${IMAGENAME}:${DOCKER_TAG}
